package com.example.administrator.familfinalcialmanagement.util.dialog;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.databinding.DialogSetTimeBinding;
import com.example.administrator.familfinalcialmanagement.util.ToastUtil;
import com.example.administrator.familfinalcialmanagement.util.listener.OnGRClickListener;

/**
 * Created by 86178 on 2019/11/24.
 * author mogen
 * 用心，成就一切。
 */

public class SetTimeDialog extends BaseDialog {

    Context context;
    DialogSetTimeBinding binding;
    OnGRClickListener listener;
    String select;

    public void setOnGRClickListener(OnGRClickListener listener) {
        this.listener = listener;
    }

    public SetTimeDialog(Context context) {
        super( context );
        this.context = context;
        binding = DataBindingUtil.inflate( LayoutInflater.from( context ), R.layout.dialog_set_time, null, false );
        binding.setDialog( this );
        setContentView( binding.getRoot() );
    }

    public void noPoint(View view) {
        if (listener != null) {
            listener.setOnCloseClick();
        }
        dismiss();
    }

    public void okPoint(View view) {
        String h = binding.etModuleHour.getText().toString().trim();
        String m = binding.etModuleMinues.getText().toString().trim();
        String s = binding.etModuleSS.getText().toString().trim();

        if (TextUtils.isEmpty( h ) || "0".equals( h )) {
            h = "00";
        }

        if (TextUtils.isEmpty( m ) || "0".equals( m )) {
            m = "00";
        }

        if (TextUtils.isEmpty( s ) || "0".equals( s ) || "00".equals( s )) {
            ToastUtil.showToast( "请输入秒数" );
            binding.etModuleSS.setText( "" );
            return;
        }

        if (Integer.valueOf( m ) > 59) {
            ToastUtil.showLongToast( "请输入59以内数据" );
            binding.etModuleMinues.setText( "" );
            return;
        }

        if (Integer.valueOf( s ) > 59) {
            ToastUtil.showToast( "请输入59以内数据" );
            binding.etModuleSS.setText( "" );
            return;
        }




        if (h.length() == 1) {
            h = "0" + s;
        }

        if (m.length() == 1) {
            m = "0" + s;
        }

        if (s.length() == 1) {
            s = "0" + s;
        }

        select = h + ":" + m + ":" + s;

        if (listener != null) {
            listener.setOnConfirmClick( select );
        }
        dismiss();
    }

}